#include<iostream>
#include<vector>
#include<numeric>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;

int n, m;
int du[N];

struct DSU {
    std::vector<int> f, sz;
    DSU() {}
    DSU(int n) { init(n); }
    void init(int n) {
        n++;
        f.resize(n);
        std::iota(f.begin(), f.end(), 0);
        sz.assign(n, 1);
    }
    int find(int x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    int size(int x) {
        return sz[find(x)];
    }
    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        sz[x] += sz[y];
        f[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

void solve()
{
    while (cin >> n, n) {
        for (int i = 1;i <= n;i++) du[i] = 0;
        DSU dsu(n);
        cin >> m;
        for (int i = 1;i <= m;i++) {
            int x, y;cin >> x >> y;
            du[x]++;du[y]++;
            dsu.merge(x, y);
        }
        int flag = 1;
        for (int i = 1;i <= n;i++) if (du[i] % 2 == 1) { flag = 0;break; }
        if (dsu.size(1) != n) flag = 0;
        cout << flag << '\n';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}